<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            position: relative;
            width: 200px;
            height: 200px;
            background-color: lightgreen;
        }
        .inner{
            width: 400px;
            height: 400px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="box">
        
    </div>

    <script>
        var box = document.querySelector('.box');
        
        console.log('box.clientWidth', box.clientWidth); // 200
        console.log('box.clientHeight', box.clientHeight); // 200

        box.style.border = '20px solid red';
        console.log('box.clientWidth', box.clientWidth); // 200
        console.log('box.clientHeight', box.clientHeight); // 200

        box.style.padding = '50px';
        console.log('box.clientWidth', box.clientWidth); // 300
        console.log('box.clientHeight', box.clientHeight); // 300

        box.innerHTML = '<div class="inner"></div>';
        console.log('box.clientWidth', box.clientWidth); // 300
        console.log('box.clientHeight', box.clientHeight); // 300

        box.style.overflow = 'scroll';
        console.log('box.clientWidth', box.clientWidth); // 283
        console.log('box.clientHeight', box.clientHeight); // 283

        console.log('box.clientTop', box.clientTop); // 20
        console.log('box.clientLeft', box.clientLeft); // 20

        // 添加盒模型
        box.style.boxSizing  = 'border-box';
        console.log('box.clientWidth', box.clientWidth); // 143
        console.log('box.clientHeight', box.clientHeight); // 143
        console.log('box.clientTop', box.clientTop); // 20
        console.log('box.clientLeft', box.clientLeft); // 20

    </script>
</body>
</html>